package com.example.springlearn.util;

import javax.servlet.http.Cookie;

public class CookieUtil {

    public static Cookie getCookieByKey(Cookie[] cookies, String key) {
        for (Cookie cookie : cookies) {
            if (cookie.getName().equals(key)) {
                return cookie;
            }
        }

        return null;
    }

    public static Cookie[] delCookies(Cookie[] cookies) {
        for (Cookie cookie : cookies) {
            cookie.setMaxAge(0);
            cookie.setPath("/");
        }
        return cookies;
    }

    public static Cookie newAllPathCookie(String name, String value) {
        Cookie cookie = new Cookie(name, value);
        cookie.setPath("/");
        return cookie;
    }

}
